package com.ruoyi.wechat.handler;


import com.ruoyi.common.utils.Json;
import com.ruoyi.wechat.domain.WxWxMsg;
import com.ruoyi.wechat.service.WxWxMsgService;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 微信回调信息
 *
 * @author yan
 * @date 2022-07-18
 */
@Component
public class LogHandler extends AbstractHandler {
    @Autowired
    WxWxMsgService wxMsgService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        try {
            this.logger.debug("\n接收到请求消息，内容：{}", Json.toJsonString(wxMessage));
            //判断event事件 存在后发送模板消息
            if ("PUBLISHJOBFINISH".equals(wxMessage.getEvent())) {
                //公众号发布推文信息


            } else if ("MASSSENDJOBFINISH".equals(wxMessage.getEvent())) {
                //公众号群发回调
            }
            wxMsgService.addWxMsg(new WxWxMsg(wxMessage));
        } catch (Exception e) {
            this.logger.error("记录消息异常", e);
        }

        return null;
    }

}
